'use strict';
(function() {
	
	function initParams($scope, $state, Dialog, service, settingService){
		$scope.ip = $state.params.ip;
		$scope.port = $state.params.port;
		$scope.monitor = $state.params.monitor;
		$scope.monitoring = null;
		$scope.logs = null;
		
		$scope.showLoginfo = function(log){
			$state.go("main.ma.loginfo", {ip:$scope.ip, port:$scope.port, monitor:$scope.monitor, name:log});
		};
		
		$scope.delLog = function($event, log){
			if(!$scope.ip || !$scope.port || !$scope.monitor){
				return;
			}
			Dialog.confirm("是否确认删除此监控日志？", function(){
				service.del($scope.ip, $scope.port, $scope.monitor, log, function(rst){
					init($scope, $state, Dialog, service);
				});
			});
			$event.stopPropagation();
		};
		
		$scope.start = function(){
			if(!$scope.ip || !$scope.port || !$scope.monitor){
				return;
			}
			settingService.start($scope.ip, $scope.port, $scope.monitor, function(rst){
				init($scope, $state, Dialog, service);
			});
		};
		
		$scope.stop = function(){
			if(!$scope.ip || !$scope.port || !$scope.monitor){
				return;
			}
			settingService.stop($scope.ip, $scope.port, $scope.monitor, function(rst){
				init($scope, $state, Dialog, service);
			});
		};
	}
	
	function init($scope, $state, Dialog, service){
		if($scope.ip && $scope.port && $scope.monitor){
			service.list($scope.ip, $scope.port, $scope.monitor, function(rst){
				$scope.monitoring = rst.data.monitoring;
				$scope.logs = rst.data.logs;
			});
		}else {
			Dialog.show("请求参数不正确！");
		}
	}
	
    ngApp.controller("malogController", ["$scope", "$state", "Dialog", 'AppConfigConstant', "malogService", "masettingService", function($scope, $state, Dialog, AppConfigConstant, malogService, masettingService) {
    	initParams($scope, $state, Dialog, malogService, masettingService);
    	init($scope, $state, Dialog, malogService);
    }]);

})();
